package nautilus.tank.model;

import nautilus.tank.coord.Coordinator3D;

public abstract class BattleObject implements IBattleObject{
	protected volatile float x;
	protected volatile float y;
	protected volatile float z;
	protected volatile float width, height;
	protected boolean selected;
	protected Coordinator3D coord;
	protected Plane plane;
	
	public float getX(){
		return x;
	}
	
	public void setX(float x){
		this.x = x;
	}
	
	public float getY(){
		return y;
	}
	
	public void setY(float y){
		this.y = y;
	}
	
	public float getZ(){
		return z;
	}
	
	public void setZ(float z){
		this.z = z;
	}
	
	public boolean isSelected(){
		return selected;
	}
	
	public void setSelected(boolean sel){
		this.selected = sel;
	}
	
	public boolean isInsideShape(float px, float py){
		float dx = Math.abs(x - px);
		float dy = Math.abs(y - py);
		
		if( (dx < width/2) && 
				(dy < height/2))
			return true;
		
		return false;
	}
	
	public float[] getLeftTop(){
		float[] p = new float[2];
		p[0] = x - width/2;
		p[1] = y - height/2;
		return p;
	}
	
	public float[] getRightTop(){
		float[] p = new float[2];
		p[0] = x + width/2;
		p[1] = y - height/2;
		return p;
	}
	public float[] getLeftBottom(){
		float[] p = new float[2];
		p[0] = x - width/2;
		p[1] = y + height/2;
		return p;
	}
	public float[] getRightBottom(){
		float[] p = new float[2];
		p[0] = x + width/2;
		p[1] = y + height/2;
		return p;
	}
	
	public abstract void onActionOrder(ActionOrder ao);

	public Coordinator3D getCoord() {
		return coord;
	}

	public void setCoord(Coordinator3D coord) {
		this.coord = coord;
	}

	public Plane getPlane() {
		return plane;
	}

	public void setPlane(Plane plane) {
		this.plane = plane;
	}
}